<?php
// ------------------------------------------------------------------------------------
// Bestand:       Email Message
// Versie:        2.0
// Projekt:       Cursus MasterClass van Eduvision
// Datum:         14-07-2008
// Auteur(s):     Ronald Obbens
// Email(s):      ronaldobbens@gmail.com
// Revisie(s):	  2.0 Headers can be included
//
// Beschrijving:  the Mail message class contains the data nescesary to send a mail
// ------------------------------------------------------------------------------------
//

include_once('iMailMessage.php');
require_once('Smarty.class.php'); 
require_once('Mailsender.php');

class MailMessage extends Mailsender implements iMailMessage
{
	private $m_aHeaders;
	private $m_aRecipients;
	private $m_sSubject;
	private $m_sMessage;
	private $m_sType;
	private $m_oSmarty;
	
	public function __construct()
	{
		$this->m_oSmarty = new Smarty();
		
		//smarty configureren
		$this->m_oSmarty->template_dir = DOCUMENT_ROOT . 'views';
		$this->m_oSmarty->config_dir = SMARTY_ROOT . 'configs';
		$this->m_oSmarty->compile_dir = SMARTY_ROOT . 'templates_c';
	}
	
	/**
	 * Add a headerrule to the email header
	 *
	 * @param string $p_sKey, Name of the headerrule
	 * @param string $p_sValue, Value of the header rule
	 */
	public function addHeader($p_sKey, $p_sValue)
	{
		$this->m_aHeaders[$p_sKey] = $p_sValue;
	}
	
	/**
	 * Add recipient to the email message
	 *
	 * @param string $p_sEmail, Emailadress recipient
	 */
	public function addRecipient($p_sEmail)
	{
		$this->m_aRecipients[] = $p_sEmail;
	}
	
	/**
	 * set the subject of the message
	 *
	 * @param string $p_sSubject
	 */
	public function setSubject($p_sSubject)
	{
		$this->m_sSubject = $p_sSubject;
	}
	
	/**
	 * Set content of the message
	 *
	 * @param string $p_sMessageContent
	 */
	public function setMessageContent($p_sMessageContent)
	{
		$this->m_sMessage = $p_sMessageContent;
	}
	
	/**
	 * set message type to HTML of PlainTEXT
	 *
	 * @param string $p_sMessageType
	 */
	public function setMessageType($p_sMessageType)
	{
		$this->m_sType = $p_sMessageType;
	}

	/**
	 * get an string with the headers
	 *
	 * @return string
	 */
	public function getHeaders()
	{
		$headers = null;
		
		foreach ($this->m_aHeaders as $header)
		{
			$headers .= $header . '\r\n';
		}
		
		return $headers;
	}
	
	/**
	 * Get the recipients of the mailmessage
	 *
	 * @return string
	 */
	public function getRecipients()
	{
		$recipients = null;
		
		foreach($this->m_aRecipients as $recipient)
		{
			$recipients .= $recipient . ',';
		}
		
		return $recipients;
	}
	
	/**
	 * get the subject of the mail
	 *
	 * @return string
	 */
	public function getsubject()
	{
		return $this->m_sSubject;
	}
	
	/**
	 * get the message of the email
	 *
	 * @return string
	 */
	public function getMessage()
	{
		return $this->m_sMessage;
	}
	
	
	/**
	 * get the type of the mail HTML of PlainText
	 *
	 * @return string
	 */
	public function getMailType()
	{
		return $this->m_sType;
	}
	
	/**
	 * assign a value to use in a mail
	 *
	 * @param unknown_type $p_sKey
	 * @param unknown_type $p_cItem
	 */
	public function assign($p_sKey,$p_cItem)
	{
		$this->m_oSmarty->assign($p_sKey,$p_cItem);
	}
	
	/**
	 * make the mesaage
	 *
	 * @param unknown_type $p_sMailTemplate
	 */
public function setMessage($p_sMailTemplate)
	{
		$this->m_sMessage = $this->m_oSmarty->fetch($p_sMailTemplate);
	}
	
	/**
	 * send current message
	 *
	 */
	public function send()
	{
		$this->sendMailMessage($this);
	}
}
?>